package com.tianji.learning.listener;

import com.tianji.api.dto.trade.OrderBasicDTO;
import com.tianji.common.constants.MqConstants;
import com.tianji.learning.service.ILearningLessonService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class PayRefundListener {

    @Autowired
    private ILearningLessonService lessonService;

    @RabbitListener(bindings = @QueueBinding(
            value=@Queue(name=MqConstants.Queue.LEARNING_LESSON_REFUND_QUEUE),
            exchange = @Exchange(name=MqConstants.Exchange.ORDER_EXCHANGE, type = ExchangeTypes.TOPIC),
            key = MqConstants.Key.ORDER_REFUND_KEY
    ))
    public void onRefund(OrderBasicDTO dto){
        lessonService.removeUserCourses(dto.getUserId(), dto.getCourseIds());
    }
}